home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr48 / tsbat146.zip / UNPACK.BAT < prev    next >
DOS Batch File  |  1992-08-27  |  5KB  |  156 lines

  1. echo off
  2. echo.
  3. echo ┌─────────────────────────────────────────────┐
  4. echo │ Unpack, test, or view any kind of archive   │
  5. echo │ By Prof. Timo Salmi, ts@uwasa.fi, 27-Aug-92 │
  6. echo └─────────────────────────────────────────────┘
  7.  
  8. rem When one writes many utilities, getting new ideas is the more critical
  9. rem part than the actual programming. Sometimes it is difficult to pinpoint
  10. rem where exactly the ideas come from, but this one clearly owes an
  11. rem acknowledgement to the posting by John LaRue (7 Mar 90) in the InterNet
  12. rem news in comp.binaries.ibm.pc.d for the general idea. All the details,
  13. rem the idea of using switches and using the file list, and the actual
  14. rem programming are entirely my own, though.
  15.  
  16. if "%1"=="" goto _help
  17.  
  18. for %%f in (%1) do if "%1"=="%%f" goto :_testext
  19. echo.
  20. echo Wildcards not allowed in %1
  21. set _choice=_usage
  22. goto _usage
  23.  
  24. :_testext
  25. rem Check that no extension was used
  26. set _exten=%1
  27. :_nextchar
  28. set _prev=%_exten%
  29. for %%f in (/%_exten%) do set _exten=%%f
  30. if ".%_exten%"=="%_prev%" goto _extfound
  31. if not "%_exten%"=="%_prev%" goto _nextchar
  32. goto _noext
  33.  
  34. :_extfound
  35. echo.
  36. echo    ******** NO EXTENSION ALLOWED ********* 
  37. set _choice=_usage
  38. goto _usage
  39.  
  40. :_noext
  41. rem Get the arhive name, the parameters, and the filenames
  42. set _choice=_usage
  43. set _archive=%1
  44. set _files=
  45. :_loop
  46. shift
  47. if "%1"=="" goto %_choice%
  48. if "%1"=="/e" set _choice=_extract
  49. if "%1"=="/e" goto _loop
  50. if "%1"=="/E" set _choice=_extract
  51. if "%1"=="/E" goto _loop
  52. if "%1"=="/t" set _choice=_test
  53. if "%1"=="/t" goto _loop
  54. if "%1"=="/T" set _choice=_test
  55. if "%1"=="/T" goto _loop
  56. if "%1"=="/v" set _choice=_view
  57. if "%1"=="/v" goto _loop
  58. if "%1"=="/V" set _choice=_view
  59. if "%1"=="/V" goto _loop
  60. set _files=%_files% %1
  61. goto _loop
  62.  
  63. :_extract
  64. set _return=_extr1
  65. goto _subru
  66. :_extr1
  67. if "%_type%"=="arc" pkunpak -e %_archive%.arc %_files%
  68. if "%_type%"=="zip" pkunzip %_archive%.zip %_files%
  69. if "%_type%"=="lzh" lha e %_archive%.lzh %_files%
  70. if "%_type%"=="zoo" zoo e %_archive%.zoo %_files%
  71. if "%_type%"=="pak" pak e %_archive%.pak %_files%
  72. if "%_type%"=="sdn" pak e %_archive%.sdn %_files%
  73. if "%_type%"=="arj" arj e %_archive%.arj %_files%
  74. goto _out
  75.  
  76. :_test
  77. set _return=_test1
  78. goto _subru
  79. :_test1
  80. if "%_type%"=="arc" pkunpak -t %_archive%.arc %_files%
  81. if "%_type%"=="zip" pkunzip -t %_archive%.zip %_files%
  82. if "%_type%"=="lzh" lha t %_archive%.lzh %_files%
  83. if "%_type%"=="zoo" zoo -test %_archive%.zoo %_files%
  84. if "%_type%"=="pak" pak t %_archive%.pak %_files%
  85. if "%_type%"=="sdn" pak t %_archive%.sdn %_files%
  86. if "%_type%"=="arj" arj t %_archive%.arj %_files%
  87. goto _out
  88.  
  89. :_view
  90. set _return=_view1
  91. goto _subru
  92. :_view1
  93. if "%_type%"=="arc" pkunpak -v %_archive%.arc %_files%
  94. if "%_type%"=="zip" pkunzip -v %_archive%.zip %_files%
  95. if "%_type%"=="lzh" lha v %_archive%.lzh %_files%
  96. if "%_type%"=="zoo" zoo v %_archive%.zoo %_files%
  97. if "%_type%"=="pak" pak v %_archive%.pak %_files%
  98. if "%_type%"=="sdn" pak v %_archive%.sdn %_files%
  99. if "%_type%"=="arj" arj v %_archive%.arj %_files%
  100. goto _out
  101.  
  102. rem Subroutine for identifying the archive type and parsing the archive name
  103. rem If the same archive has been packed with several methods .arc takes
  104. rem precedence, then .zip, and so on
  105. :_subru
  106. set _type=
  107. if exist %_archive%.arj set _type=arj
  108. if exist %_archive%.sdn set _type=sdn
  109. if exist %_archive%.pak set _type=pak
  110. if exist %_archive%.zoo set _type=zoo
  111. if exist %_archive%.lzh set _type=lzh
  112. if exist %_archive%.zip set _type=zip
  113. if exist %_archive%.arc set _type=arc
  114. if "%_type%"=="" goto _notfound
  115. goto %_return%
  116.  
  117. rem Archive does not exist
  118. :_notfound
  119. echo.
  120. echo File %_archive%.arc[.zip.lzh.zoo.pak.sdn.arj] not found
  121. set _choice=_usage
  122. goto _usage
  123.  
  124. :_help
  125. :_usage
  126. echo.
  127. echo Usage: UNPACK ArchiveName [FileNames] { /e : /t : /v }
  128. echo                                          │    │    └─ view contents
  129. echo                                          │    └─ test integrity
  130. echo                                          └─ extract files
  131. echo ┌───────────────────────────────────────────┐┌───────────────────────────┐
  132. echo │ Archive name: NO WILDCARDS! NO EXTENSION! ││ One switch must be chosen │
  133. echo └───────────────────────────────────────────┘└───────────────────────────┘
  134. if "%_choice%"=="_usage" goto _out
  135. echo.
  136. echo Examples: UNPACK b:\tsutil35 /v d*.exe
  137. echo.
  138. echo Before you can use this batch, you must make the following programs
  139. echo available at your path (or include the relevant paths in the batch):
  140. echo pkunpak.exe, pkunzip.exe, lha.exe, pak.exe, zoo.exe, and arj.exe.
  141. echo.
  142. echo If you get an "Out of environment space" message, increase your
  143. echo environment space by using shell configuration in config.sys:
  144. echo MsDos 3.30 example: shell=c:\bin\command.com /e:1024 /p
  145. goto _out
  146.  
  147. :_out
  148. set _choice=
  149. set _archive=
  150. set _files=
  151. set _type=
  152. set _return=
  153. set _exten=
  154. set _prev=
  155. echo on
  156.